﻿#ifndef _SLT_THREAD_POOL_H_20220117
#define _SLT_THREAD_POOL_H_20220117

/* thread pool */

#include <string>
#include <functional>
#include <mutex>
#include <deque>
#include <thread>
#include <condition_variable>

class slt_thread_task
{
public:
    virtual ~slt_thread_task() {};
    virtual void onRun() = 0;
    virtual void destory() {
        delete this;
    }
};

class slt_thread_pool
{
public:
    int init(int _tNum);
    //int destroy();

    int post_task(slt_thread_task* _ptask);

private:
    void thread_pool_cycle();
private:
    bool                    m_threadRun = false;
    std::mutex              m_mutex;
    std::condition_variable m_cond;

    std::deque<slt_thread_task*>  m_taskList;

    std::deque<std::thread*>      m_threadList;
};



#endif /* _THREAD_POOL_H_ */